class Solution {
public:
    vector<int> findMissingAndRepeatedValues(vector<vector<int>>& grid) {
        vector<int>ans(2);
        int n = grid.size();
        vector<int>mp(n * n + 1);
        for (auto x : grid) {
            for (auto y : x) {
                mp[y]++;
            }
        }
        for (int i = 1; i <= n * n; i++) {
            if (mp[i] == 2)ans[0] = i;
            else if (!mp[i])ans[1] = i;
        }
        return ans;
    }
};